//
//  CollectionCellForCell.m
//  MY Project For Sport
//
//  Created by dllo on 16/2/29.
//  Copyright © 2016年 dilo. All rights reserved.
//

#import "CollectionCellForCell.h"
#import <DKNightVersion.h>
#import "UIColor+Wonderful.h"

#define WEIGHTT [UIScreen mainScreen].bounds.size.width / 375
#define HEIGHTT [UIScreen mainScreen].bounds.size.height / 667


@interface CollectionCellForCell ()

@property (nonatomic, assign)CGSize width;

@end

@implementation CollectionCellForCell

- (void)dealloc {
    
    
    [_history release];
    [super dealloc];

}

- (instancetype)initWithFrame:(CGRect)frame {

    self = [super initWithFrame:frame];
    
    if (self) {
        
        self.history = [[UILabel alloc] init];
        [self.contentView addSubview:self.history];
        [_history release];
        self.contentView.backgroundColor = [UIColor lightCyan];;
        self.contentView.layer.cornerRadius = 8;
        self.contentView.layer.masksToBounds = YES;
        
        self.buttonForDelete = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.contentView addSubview:self.buttonForDelete];
        self.buttonForDelete.hidden = YES;
        
        [self.buttonForDelete addTarget:self action:@selector(delectAction:) forControlEvents:UIControlEventTouchUpInside];
        
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleShowDelete:) name:@"showDelete" object:nil];
        
        
    }

    return self;


}



- (void)handleShowDelete:(NSNotification *) notfication {
    
    // 显示 button
    self.buttonForDelete.hidden = NO;
    
}


- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {


    self.history.frame = CGRectMake(10 * WEIGHTT, 10 * HEIGHTT, self.contentView.frame.size.width - 20 * WEIGHTT , self.contentView.frame.size.height -20 * HEIGHTT);
    self.history.textAlignment = NSTextAlignmentCenter;

    
    self.buttonForDelete.frame = CGRectMake(0, 0,20 * WEIGHTT, 20 * HEIGHTT);
    [self.buttonForDelete setImage:[UIImage imageNamed:@"iconfont-cha"] forState:UIControlStateNormal];
 
}

- (void)passModelForHistory:(NSString *)text {

    self.history.text = text;
    
}

- (void)delectAction:(UIButton *)buttton {
    
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"delect" object:nil userInfo:@{@"index":self.history.text}];
    //[NSNotificationCenter defaultCenter] pos
    
}


@end
